package com.purchase.rest;

import com.purchase.service.MemberOrderService;
import com.purchase.service.MemberPayService;
import com.purchase.service.MemberRefundService;
import com.purchase.util.RequestForm;
import com.purchase.util.ResponseForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberOrderService memberOrderService;

    @Autowired
    private MemberPayService memberPayService;

    @Autowired
    private MemberRefundService memberRefundService;

    /**
     * 购买会员
     *
     * @param param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    public ResponseForm createOrder(@RequestBody RequestForm param) {
        return memberOrderService.createOrder(param);
    }

    /**
     * 支付结果通知
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/payNotify")
    public String payNotify(HttpServletRequest request) {
        return memberPayService.payNotify(request);
    }

    /**
     * 申请退款
     *
     * @param param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/refund", method = RequestMethod.POST)
    public ResponseForm refund(@RequestBody RequestForm param) {
        return memberRefundService.refund(param);
    }

    /**
     * 退款结果通知
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/refundNotify")
    public String refundNotify(HttpServletRequest request) {
        return memberRefundService.refundNotify(request);
    }

    /**
     * 退款审核
     *
     * @param param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/refundAudit", method = RequestMethod.POST)
    public ResponseForm refundAudit(@RequestBody RequestForm param) {
        return memberRefundService.refundAudit(param);
    }

    /**
     * 退款查询
     *
     * @param param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/refundQuery", method = RequestMethod.POST)
    public ResponseForm orderQuery(@RequestBody RequestForm param) {
        return memberRefundService.refundQuery(param);
    }

    /**
     * 会员订单列表
     *
     * @param param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderListByStatus", method = RequestMethod.POST)
    public ResponseForm getOrderListByStatus(@RequestBody RequestForm param) {
        return memberOrderService.getOrderListByStatus(param);
    }

}
